package org.skycloud.mybatis.dialect.impl;

import org.apache.ibatis.session.RowBounds;
import org.skycloud.mybatis.dialect.Dialect;
import org.skycloud.mybatis.utils.StringBuilderUtils;

public final class MySQLDialect implements Dialect {

	private static final String LIMIT = " limit ";
	private static final String COMMA = ", ";

	@Override
	public String getSql(String sql, RowBounds rowBounds) {
		if (rowBounds.getOffset() > 0) {
			return StringBuilderUtils.getThreadLocalStringBuilder(0).append(sql).append(LIMIT)
					.append(rowBounds.getOffset()).append(COMMA).append(rowBounds.getLimit()).toString();
		} else {
			return StringBuilderUtils.getThreadLocalStringBuilder(0).append(sql).append(LIMIT)
					.append(rowBounds.getLimit()).toString();
		}
	}
}
